// cf-142c
// 题意：给定一个n*m(<=9)的方格，用3*3的四个方向的T形去填充，问最多能填
//       几个，并输出任意一种方案（用26个字母标识）。
//
// 题解：可以暴搜吧。用状态压缩练练手。
// 
// run: $exec < input
// opt: 0
// flag: -g
#include <iostream>
#include <utility>

int const maxn = 10;
int f[maxn + 4][1 << maxn][1 << maxn];
int p5[maxn];
using pair_type = std::pair<int, int>;
pair_type from[maxn + 4][1 << maxn][1 << maxn];
int way[maxn + 4][1 << maxn][1 << maxn];
int gps, gpps;
int n, m;

void dfs(int row, int ps, int pps, int col, int now, int count, int tway) // p = prev, s = state, col start from 0
{
	if (col == m) {
		if (f[row + 1][now][ps] < f[row][gps][gpps] + count) {
			f[row + 1][now][ps] = f[row][gps][gpps] + count;
			from[row + 1][now][ps] = {gps, gpps};
			way[row + 1][now][ps] = tway;
		}
		return;
	}
	// empty
	dfs(row, ps, pps, col + 1, now, count, tway);
	if (col + 3 > m) return;
	// |--
	if (!(now & (1 << col)) && !(pps & (1 << col)) && !(ps & (1 << col)) && !(ps & (1 << (col + 1))) && !(ps & (1 << (col + 2)))) {
		int tps = ps | (1 << col) | (1 << (col + 1) | (1 << (col + 2)));
		int tpps = pps | (1 << col);
		dfs(row, tps, tpps, col + 2, now | (1 << col), count + 1, tway + p5[col] * 1);
	}
	// T
	if (!(pps & (1 << col)) && !(pps & (1 << (col + 1))) && !(pps & (1 << (col + 2))) && !(ps & (1 << (col + 1)))) {
		int tps = ps | (1 << (col + 1));
		int tpps = pps | (1 << col) | (1 << (col + 1)) | (1 << (col + 2));
		dfs(row, tps, tpps, col + 2, now | (1 << (col + 1)), count + 1, tway + p5[col] * 2);
	}
	// _|_
	if (!(now & (1 << col)) && !(ps & (1 << (col + 1))) && !(pps & (1 << (col + 1)))) {
		int tps = ps | (1 << (col + 1));
		int tpps = pps | (1 << (col + 1));
		dfs(row, tps, tpps, col + 2, now | (1 << col) | (1 << (col + 1)) | (1 << (col + 2)), count + 1, tway + p5[col] * 3);
	}

	// -|
	if (!(ps & (1 << col)) && !(ps & (1 << (col + 1))) && !(ps & (1 << (col + 2))) && !(pps & (1 << (col + 2)))) {
		int tps = ps | (1 << col) | (1 << (col + 1) | (1 << (col + 2)));
		int tpps = pps | (1 << (col + 2));
		dfs(row, tps, tpps, col + 3, now | (1 << (col + 2)), count + 1, tway + p5[col] * 4);
	}
}

char out[maxn][maxn];

void print(pair_type s)
{
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) out[i][j] = '.';
	int tot = 0;
	for (int i = n; i > 2; i--) {
		int ts = way[i][s.first][s.second];
		for (int j = 1; j <= m; j++, ts /= 5) {
			int t = ts % 5;
			if (!t) continue;
			if (t == 1) {
				out[i][j] = out[i - 1][j] = out[i - 2][j] = out[i - 1][j + 1]
					= out[i - 1][j + 2] = 'A' + tot++;
			} else if (t == 2) {
				out[i - 2][j] = out[i - 2][j + 1] = out[i - 2][j + 2] = out[i - 1][j + 1]
					= out[i][j + 1] = 'A' + tot++;
			} else if (t == 3) {
				out[i][j] = out[i][j + 1] = out[i][j + 2] = out[i - 1][j + 1]
					= out[i - 2][j + 1] = 'A' + tot++;
			} else {
				out[i - 1][j] = out[i - 1][j + 1] = out[i - 1][j + 2] = out[i - 2][j + 2]
					= out[i][j + 2] = 'A' + tot++;
			}
		}
		s = from[i][s.first][s.second];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) std::cout << out[i][j];
		std::cout << '\n';
	}
}

int main()
{
	std::ios::sync_with_stdio(false);
	p5[0] = 1;
	for (int i = 1; i < maxn; i++) p5[i] = p5[i - 1] * 5;
	std::cin >> n >> m;
	for (int i = 0; i <= n; i++)
		for (int j = 0; j < (1 << m); j++)
			for (int k = 0; k < (1 << m); k++) f[i][j][k] = -1;
	f[2][0][0] = 0;
	for (int i = 2; i <= n; i++) {
		for (gps = 0; gps < (1 << m); gps++)
			for (gpps = 0; gpps < (1 << m); gpps++) {
				if (f[i][gps][gpps] == -1) continue;
				dfs(i, gps, gpps, 0, 0, 0, 0);
			}
	}
	int max = -1;
	pair_type state;
	for (int ps = 0; ps < (1 << m); ps++) {
		for (int pps = 0; pps < (1 << m); pps++) {
			if (f[n][ps][pps] > max) {
				max = f[n][ps][pps];
				state = {ps, pps};
			}
		}
	}

	std::cout << std::max(0, max) << '\n';
	print(state);
}

